<template>
    <div class="fromBox">
        <el-form ref="ruleForm" :model="ruleForm" :rules="rules">
            <el-form-item prop="title">
                <el-input v-model="ruleForm.title" size="small" placeholder="项目名称"></el-input>
            </el-form-item>
            <el-form-item prop="description">
                <el-input v-model="ruleForm.description" rows="28" resize="none" placeholder="项目简介" type="textarea" size="small">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { mapState } from 'vuex';
export default {
    props: ['closeEvent'],
    computed: {
        ...mapState("mainOptions", {
            projectData: state => state.project,
            service: state => state.service,
        }),
    },
    data() {
        return {
            project: {},
            ruleForm: {
                title: '',
                description: '',
            },
            rules: {
                title: { required: true, message: '请输入项目名', trigger: 'change' },
            }
        }
    },
    mounted() {
        this.project = JSON.parse(JSON.stringify(this.projectData));
        this.ruleForm.title = this.project.title;
        this.ruleForm.description = this.project.description;
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    // action=>
                    window.action.project.editDetail(this.project.projectId, this.ruleForm).then((res) => {
                        if (res) {
                            this.$store.dispatch('mainOptions/setProjectDetail', this.ruleForm);
                            this.$alert('操作成功');
                            this.$electron.ipcRenderer.send('updata-window-param', JSON.stringify({
                                winId: this.$win.id,
                                title: this.ruleForm.title,
                                description: this.ruleForm.description,
                            }));
                            this.closeEvent();
                        };
                    });
                } else {
                    return false;
                }
            });
        }
    },
}
</script>

<style scoped>
    .fromBox { padding: 0 40px;}


</style>